package utils

import (
	"fmt"
	"github.com/tedcy/fdfs_client"
)

// AddDomain2Url 将url加上 http://IP:PROT/ 前缀/
func AddDomain2Url(url string) (domainUrl string) {
	domainUrl = "http://" + GServerAddr + ":" + GFastdfsPort + "/" + url

	return domainUrl
}

// 上传二进制文件到fdfs中的操作
func UploadByBuffer(fileBuffer []byte, fileExt string) (fileId string, err error) {
	//fd_client, err := fdfs_client.NewClientWithConfig("/Users/jackli/git/ihome/conf/client.conf")
	fd_client, err := fdfs_client.NewClientWithConfig("./conf/client.conf")
	if err != nil {
		fmt.Println("fdfs创建句柄失败",err)
		fileId = ""
		return
	}
	fd_rsp, err := fd_client.UploadByBuffer(fileBuffer, fileExt)
	if err != nil {
		fmt.Println("上传失败",err)
		fileId = ""
		return
	}
	fmt.Println(fd_rsp)
	return fd_rsp, nil
}
